package com.sprucetec.live.aspect;

import com.sprucetec.live.entity.LiveVideo;
import com.sprucetec.live.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

/**
 * @ClassName LiveRedisCacheAspect
 * @Description:
 * @Author Kenny
 * @Date 2020/4/4
 **/
@Aspect
@Component
@Slf4j
public class LiveRedisCacheAspect {

    @Autowired
    RedisService redisService;

    @Qualifier("threadPoolTaskExecutor")
    @Autowired
    ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @AfterReturning(returning = "rvt", pointcut = "@annotation(com.sprucetec.live.annotation.LiveRedisCache)")
    public Object AfterReturning(JoinPoint joinPoint, Object rvt) {
        log.info("后置处理. 处理视频分类缓存");
        LiveVideo liveVideo = (LiveVideo) rvt;
        threadPoolTaskExecutor.execute(()->{
            redisService.videoChangeRefreshCache(liveVideo);
        });
        return rvt;
    }

}
